<template>
	<view :class="{lottery_box: bargainList.length > 0}">
		<nav-bar ref="navBar" :shadow="false" title="我的砍价" fontColor="#FFF" bgColor="themeBgColor">
		</nav-bar>
        <!-- 公共组件-每个页面必须引入 -->
        <public-module></public-module>
        <mescroll-body ref="mescrollRef" @init="mescrollInit" :down="downOption" @down="downCallback" @up="upCallback">
            <view class="bargain_item_box">
                <my-bargain-goods-item  v-for="(item,index) of bargainList" :key="index" :item="item" :index="index"></my-bargain-goods-item>
            </view>
        </mescroll-body>
	</view>
</template>

<script>
    import myBargainGoodsItem from './components/my_bargain_goods_item';
	import MescrollMixin from "@/components/common/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], // 使用mixin (在main.js注册全局组件)
        components: {
            myBargainGoodsItem
        },
		data() {
			return {
				scrollTop: 0,
				statusBarHeight: 0,
				pageScroll: 0,
                downOption: {
                	auto: false //是否在初始化后,自动执行downCallback; 默认true
                },
                bargainList: [],
			};
		},
		computed: {

		},
		//第一次加载
		onLoad(e) {
			//获取手机状态栏高度
			this.statusBarHeight = uni.getSystemInfoSync()['statusBarHeight'];
		},
		//页面显示
		onShow() {},
		//方法
		methods: {
			onPageJump(url) {
				uni.navigateTo({
					url: url
				});
			},
            /*下拉刷新的回调 */
            downCallback() {
            	//联网加载数据
            	this.loadData(1);
            },
            /*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
            upCallback(page) {
            	//联网加载数据
            	this.loadData(page.num);
            },
            loadData(pageNo) {
                let httpData = {
                    pageNo: pageNo,
                    pageSize: 15,
                };
                this.$http
                	.post('api/order_mall_cut/v1/my_cuts', httpData,{
                		load:false
                	}).then(res => {
                		uni.stopPullDownRefresh();
                		//方法一(推荐): 后台接口有返回列表的总页数 totalPage
                		this.mescroll.endByPage(res.data.length, res.pages); //必传参数(当前页的数据个数, 总页数)
                		
                		if (pageNo == 1) {
                			this.bargainList = res.data;
                		} else {
                			this.bargainList = this.bargainList.concat(res.data);
                		}
                	}).catch(() => {
                		//联网失败, 结束加载
                		this.mescroll.endErr();
                	});
            },
		},
		//页面隐藏
		onHide() {},
		//页面卸载
		onUnload() {},
		onPageScroll(e) {
			this.$refs.navBar.pageScroll(e);
			this.pageScroll = e.scrollTop;
		},
		//页面下来刷新
		onPullDownRefresh() {
            this.pageNo = 1;
            this.pages = 1;
            this.loadData();
        },
		//页面上拉触底
		onReachBottom() {
            this.loadData();
        },
		//用户点击分享
		onShareAppMessage(e) {
			return this.wxShare();
		}
	};
</script>
<style lang="scss" scoped>
	@import '@/style/mixin.scss';

	.lottery_box {
		min-height: 100vh;
		// @include theme("gradient_bg");
	}

	.title {
		margin: 0 auto;
		display: flex;
	}

	// .lottery_box {
	// 	min-height: 100vh;
	// 	background-image: url(http://qn.kemean.cn/upload/202008/21/1597990635657ef2vxcd4.png);
	// 	background-size: 100% auto;
	// 	background-repeat: no-repeat;
	// 	width: 100%;
	// 	padding-top: 114rpx;
	// }

	
</style>
